package com.ming.study.controller;

import com.ming.study.pojo.Course;
import com.ming.study.pojo.UserInfo;
import com.ming.study.pojo.vo.*;
import com.ming.study.service.JwService;
import com.ming.study.utils.R;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/jw")
public class JwSystemController {
    @Autowired
    private JwService jwService;

    @GetMapping("/test")
    @ApiOperation("测试")
    public String index() {
        return "测试";
    }

    @ApiOperation("获取用户信息")
    @GetMapping("/userInfo")
    public R getUserInfo(HttpServletRequest request) {
        System.out.println("?????????????");
        UserInfo user = jwService.getUserInfo(request.getAttribute("userAccount").toString());
        return R.ok().data("user", user);
    }

    @ApiOperation("通过周次获取课表")
    @GetMapping("/courseSchedule/{date}")
    public R getCourseSchedule(HttpServletRequest request,@PathVariable String date) {
        List<List<Course>> courseSchedule = jwService.getCourseFromWeek(request.getAttribute("userAccount").toString(), date);
        return R.ok().data("courseSchedule", courseSchedule);
    }

    @ApiOperation("获取课表备注")
    @GetMapping("/courseScheduleRemark")
    public R getCourseScheduleRemark(HttpServletRequest request) {
        List<CourseScheduleRemark> courseScheduleRemarkList = jwService.getCourseScheduleRemark(request.getAttribute("userAccount").toString());
        return R.ok().data("courseScheduleRemarkList", courseScheduleRemarkList);
    }


    @ApiOperation("获取日期选项")
    @GetMapping("/selectWeekOptions")
    public R getSelectOptions(HttpServletRequest request) {
        WeekOptionsVo WeekOptionsVo = jwService.getWeekOptions(request.getAttribute("userAccount").toString());
        return R.ok().data("weekOptions", WeekOptionsVo);
    }

    @ApiOperation("获取课程成绩")
    @GetMapping("/courseScores")
    public R getCourseScores(HttpServletRequest request) {
        CourseScoresVo courseScoresVo = jwService.getCourseScores(request.getAttribute("userAccount").toString(), 0);
        return R.ok().data("courseScores", courseScoresVo);
    }

    @ApiOperation("获取默认学期")
    @GetMapping("/defaultTerm")
    public R getDefaultTerm(HttpServletRequest request) {
        String defaultTerm = jwService.getDefaultTerm(request.getAttribute("userAccount").toString());
        return R.ok().data("defaultTerm", defaultTerm);
    }

    @ApiOperation("获取所有考试安排")
    @GetMapping("/examSchedule")
    public R getExamSchedule(HttpServletRequest request) {
        List<ExamVo> allExamScheduleList = jwService.getAllExamSchedule(request.getAttribute("userAccount").toString());
        return R.ok().data("allExamScheduleList", allExamScheduleList);
    }

    @ApiOperation("获取考证成绩")
    @GetMapping("/certificateScore")
    public R getCertificateScore(HttpServletRequest request) {
        List<CertificateScoreVo> CertificateScoreList = jwService.getAllCertificateScore(request.getAttribute("userAccount").toString());
        return R.ok().data("certificateScoreList", CertificateScoreList);
    }
}
